package org.pearl.study.transmission.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {

    @Bean
    SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(e -> {
            e.anyRequest().authenticated();
        });
        // 关闭默认的表单登录
        http.formLogin(AbstractHttpConfigurer::disable);
        // 启用自定义的表单登录
        http.apply(PearlFormLoginConfigurer.customFormLogin()
                .usernameParameter("username"));
        return http.build();
    }
}